class Solution {
public:
    int searchInsert(vector<int>& nums, int target)
    {


        int left = 0, right = nums.size() - 1;
        for (; right > left;)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] < target) left = mid + 1;
            else right = mid;
        }
        if (target > nums[right]) return right + 1;
        if (target < nums[0]) return 0;
        return right;
    }
};